import { reactive } from "vue";
import { loginRequest } from "../../api/login.js";
const userInfo = reactive({
    username: "admin",
    password: "123456"
});
const loginFormRules = {
    username: [
        {
            required: true,
            message: "请输入用户名称",
            trigger: "blur"
        },
        {
            min: 3,
            max: 10,
            message: "长度在 3 到 10 个字符",
            trigger: "blur"
        }
    ],
    password: [
        {
            required: true,
            message: "请输入用户密码",
            trigger: "blur"
        },
        {
            min: 3,
            max: 6,
            message: "长度在 3 到 6 个字符",
            trigger: "blur"
        }
    ]
};
/**
 * 登录函数
 * @param {CurrentInstance} ctx vue Instance
 * @param {Router} router userRouter()
 */
const loginHandle = async (ctx, router) => {
    const { data } = await loginRequest(userInfo);
    if (data.meta.status !== 200) {
        return ctx.$message.error("登录失败");
    }
    ctx.$message.success("登录成功");
    window.sessionStorage.setItem("token", data.data.token);
    router.push("/home");
};
export default {
    userInfo, loginFormRules, loginHandle
}